#! /bin/sh

# Modified from the ant startup script to start the BeanBox example instead.

# Cygwin support.  $cygwin _must_ be set to either true or false.
case "`uname`" in
  CYGWIN*) cygwin=true ;;
  *) cygwin=false ;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin; then
  [ -n "$OPENMAP_HOME" ] &&
    OPENMAP_HOME=`cygpath --unix "$OPENMAP_HOME"`
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  [ -n "$CLASSPATH" ] &&
    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi

if [ "$OPENMAP_HOME" = "" ] ; then
  # try to find OPENMAP
  if [ -d /usr/local/openmap ] ; then 
    OPENMAP_HOME=/usr/local/openmap
  fi

  if [ -d ${HOME}/openmap ] ; then 
    OPENMAP_HOME=${HOME}/openmap
  fi

  ## resolve links - $0 may be a link to ant's home
  PRG=$0
  progname=`basename $0`
  
  while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '.*/.*' > /dev/null; then
	PRG="$link"
    else
	PRG="`dirname $PRG`/$link"
    fi

  done
  
  OPENMAP_HOME=`dirname "$PRG"`/..

fi

if [ "$JAVA_HOME" != "" ] ; then
  if [ "$JAVACMD" = "" ] ; then 
    JAVACMD=$JAVA_HOME/bin/java
  fi
else
  if [ "$JAVACMD" = "" ] ; then 
    JAVACMD=java
  fi
fi

# add in the dependency .jar files
DIRLIBS=${OPENMAP_HOME}/lib/*.jar
# Change to match your installation
for i in ${DIRLIBS}
do
    # if the directory is empty, then it will return the input string
    # this is stupid, so case for it
    if [ "$i" != "${DIRLIBS}" ] ; then
	if [ "$LOCALCLASSPATH" != "" ] ; then
	    LOCALCLASSPATH=$LOCALCLASSPATH:"$i"
	else 
	    LOCALCLASSPATH="$i"
	fi
    fi
done

LOCALCLASSPATH=$LOCALCLASSPATH:${OPENMAP_HOME}/share

if [ "$CLASSPATH" != "" ] ; then
  LOCALCLASSPATH=$CLASSPATH:${OPENMAP_HOME}/classes/openmap:${OPENMAP_HOME}/classes/corba_vb$LOCALCLASSPATH
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
  OPENMAP_HOME=`cygpath --path --windows "$OPENMAP_HOME"`
  JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  LOCALCLASSPATH=`cygpath --path --windows "$LOCALCLASSPATH"`
fi

$JAVACMD -Xmx64m -classpath "$LOCALCLASSPATH" -Dopenmap.configDir=$OPENMAP_HOME/share com.bbn.openmap.app.OpenMap -properties ./openmap.properties


